'use strict';
var calculate_median = function(collection){
  var count = 0;
  var sum = [];
  for (var i=0;i<collection.length;i++){
    if((i+1)%2==0){
      sum.push(collection[i])
      count++;
    }
  }

  if(count%2==0){
    return (sum[sum.length/2-1]+sum[sum.length/2])/2;
  }else {
    return sum[(sum.length+1)/2-1];
  }
};
module.exports = calculate_median;
